<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html {
            height: 4000px;
        }

        * {
            margin: 0;
            padding: 0;
        }

        .div1 {
            width: 100%;
            height: 200px;
            background-color: pink;
        }

        .div2 {
            width: 100%;
            height: 100px;
            background-color: skyblue;
        }

        #ma {
            width: 100%;
            height: 100px;
            background-color: tomato;
            box-sizing: border-box;
            padding-top: 25px;
        }

        #search {
            width: 1000px;
            height: 50px;
            margin: auto;
            background-color: slateblue;
            box-sizing: border-box;
            border: none;
            line-height: 20px;
            transition: 1s;
        }

        #inp {
            width: 900px;
            height: 50px;
            outline: none;
            border: none;
            box-sizing: border-box;
            padding-left: 5px;
            border-radius: 5px;

        }

        #btn {
            width: 100px;
            height: 50px;
            outline: none;
            border: none;
            border-radius: 5px;
            cursor: pointer;

        }
    </style>
</head>

<body>
    <div class="div2"></div>
    <div class="div1"></div>
    <main id="ma">
        <div id="search">
            <input type="text" name="" id="inp" placeholder="请查询"><button id="btn">🔍</button>
        </div>
    </main>
    <script>
        var ma = document.getElementById("ma")
        window.onscroll = function () {
            var h = document.documentElement.scrollTop
            if (h >= 400) {
                ma.style = `position: fixed;top:0;margin:0 auto; transition: 1s;`
            } else {
                ma.style = ``
            }
        }
    </script>
</body>

</html>